package com.ruoyi.web.controller.store.healthy;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QualityRecord;
import com.ruoyi.system.service.IQualityRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检测记录Controller
 *
 * @author ruoyi
 * @date 2023-11-27
 */
@RestController
@RequestMapping("/quality/record")
@Api(tags = "台账检测相关接口")
public class QualityRecordController extends BaseController
{
    @Autowired
    private IQualityRecordService qualityRecordService;

    /**
     * 查询检测记录列表
     */
    //("@ss.hasPermi('system:record:list')")
    @ApiOperation("台账检测列表")
    @GetMapping("/list")
    public TableDataInfo list(QualityRecord qualityRecord)
    {
        startPage();
        List<QualityRecord> list = qualityRecordService.selectQualityRecordList(qualityRecord);
        return getDataTable(list);
    }

    /**
     * 导出检测记录列表
     */
    //("@ss.hasPermi('system:record:export')")
    @ApiOperation("台账检测导出")
    @Log(title = "检测记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualityRecord qualityRecord)
    {
        List<QualityRecord> list = qualityRecordService.selectQualityRecordList(qualityRecord);
        ExcelUtil<QualityRecord> util = new ExcelUtil<QualityRecord>(QualityRecord.class);
        util.exportExcel(response, list, "检测记录数据");
    }

    /**
     * 获取检测记录详细信息
     */
    //("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("台账检测详情")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(qualityRecordService.selectQualityRecordById(id));
    }

    /**
     * 新增检测记录
     */
    //("@ss.hasPermi('system:record:add')")
    @ApiOperation("台账检测新增")
    @Log(title = "检测记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QualityRecord qualityRecord)
    {
        return toAjax(qualityRecordService.insertQualityRecord(qualityRecord));
    }

    /**
     * 修改检测记录
     */
    //("@ss.hasPermi('system:record:edit')")
    @ApiOperation("台账检测修改")
    @Log(title = "检测记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualityRecord qualityRecord)
    {
        return toAjax(qualityRecordService.updateQualityRecord(qualityRecord));
    }

    /**
     * 删除检测记录
     */
    //("@ss.hasPermi('system:record:remove')")
    @Log(title = "检测记录", businessType = BusinessType.DELETE)
    @ApiOperation("台账检测删除")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qualityRecordService.deleteQualityRecordByIds(ids));
    }
}
